package com.bonc.modules.business.controller;

import java.io.UnsupportedEncodingException;
import java.lang.reflect.Field;
import java.math.BigDecimal;
import java.security.NoSuchAlgorithmException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.concurrent.atomic.AtomicReference;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.bonc.common.param.BaseParam;
import com.bonc.common.utils.*;
import com.bonc.modules.business.entity.*;
import net.sf.json.JSONArray;
import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import com.bonc.modules.business.service.TbWorkOrderReplyService;


/**
 * 工单回复码表
 *
 * @author feiniao
 * @date 2021-10-11 11:15:48
 */
@RestController
@RequestMapping("business/tbworkorderreply")
public class TbWorkOrderReplyController {
    @Autowired
    private TbWorkOrderReplyService tbWorkOrderReplyService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("business:tbworkorderreply:list")
    public Result list(@RequestParam Map<String, Object> params){
        PageUtils page = tbWorkOrderReplyService.queryPage(params);

        return Result.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{identifier}")
    //@RequiresPermissions("business:tbworkorderreply:info")
    public Result info(@PathVariable("identifier") String identifier){
		TbWorkOrderReplyEntity tbWorkOrderReply = tbWorkOrderReplyService.getById(identifier);

        return Result.ok().put("tbWorkOrderReply", tbWorkOrderReply);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("business:tbworkorderreply:save")
    public Result save(@RequestBody TbWorkOrderReplyEntity tbWorkOrderReply){
		tbWorkOrderReplyService.save(tbWorkOrderReply);

        return Result.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public Result update(@RequestBody TbWorkOrderReplyEntity tbWorkOrderReply){
		tbWorkOrderReplyService.updateById(tbWorkOrderReply);

        return Result.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("business:tbworkorderreply:delete")
    public Result delete(@RequestBody String[] identifiers){
		tbWorkOrderReplyService.removeByIds(Arrays.asList(identifiers));

        return Result.ok();
    }

    /**
     * 省端实时工单回复集团
     * @return
     */
    @RequestMapping("/ReplyCSService")
    public Result getReplyCSService(){
        AtomicReference<String> res = tbWorkOrderReplyService.replyOrderService();
        return Result.ok().put("data",res);
    }

    /**
     * 集团给省端回复
     */
    @PostMapping({"/ReplyCSS"})
    public ReplyCommon ReplyCSS(@RequestBody @Validated({BaseParam.list.class}) TbCommonParamInfoEntity tbCommonParamValue)
            throws Exception
    {
        ReplyCommon res = tbWorkOrderReplyService.ReplyCSS(tbCommonParamValue);
        return res;
    }

    /**
     * 工单通用接口——中途意见
     * 工单处理方 必须是在回复工单之后 需要对功能内容进行补充时，调用该接口
     */
    @RequestMapping("/CurrencyCSService")
    public Result postCurrencyCSS(@RequestBody TbWorkOrderCurrencyEntity tbWorkOrderCurrencyEntity){
        AtomicReference<String> res = tbWorkOrderReplyService.postCurrencyCSS(tbWorkOrderCurrencyEntity);
        return Result.ok().put("data",res);
    }

}
